<?php
// Hello and welcome to the Skeleton module. Don't worry it's not as scary as it
// sounds. I'm assuming you are reading this comment because you are either bored
// or wish to make a module. If it's the latter then "Yay you!" :)
//
// You'll notice that this module is HEAVILY over-commented. The idea is that you
// may use the skelton module as a base module to get things up and running quickly
// and/or to teach you a thing or two. I personally advise however that when writing
// your module you take the time to remove comments as you see fit (providing you
// understand the code of course), to make things a little neater and less hectic
// for other potential eyes that may glance upon your magnificent masterpiece!
//
// Good luck!

#### SKELETON CONTROLLER #######################################################
class SkeletonController {

	#### CONSTRUCTOR ###########################################################
	function SkeletonController() {
		Base::getThis();

		// Set the page title
		$this->page_title = _('Test Module');
		if (url(2)) $this->page_title .= ' '.ucwords(url(2));

		// Make database methods ready for use
		$this->model = $this->load->model('skeleton');

		// Perform default function
		invoke_method($this, url(2));
	}

	#### MAIN ##################################################################
	function main() {
		if (url(2)) $this->view();
		else $this->list_items();
	}

	#### LIST ##################################################################
	function list_items() {
		$this->body = _('The skeleton module is a basic example of the construction of a module.
			Its purpose is for it to be used as a springboard for the creation of modules. It provides
			a basic module layout with typical module features such as a front end that demonstrates
			data retrival from a database and display. A backend with item managment which includes paginated
			item listed as well as add, edit delete functions along with a module configuration area and
			navigational header.');
		$this->body = '<br /><br />';
		$this->body = _('Good luck!');
		$this->body = '<br /><br />';

		$table = $this->load->library('table');
		$table->open();
		$table->tr(
			$table->th(_('Item ID'), 60, TRUE).
			$table->th(_('Item Link'))
		);

		$items = $this->model->getEnabledItems();

		if ($items) foreach ($items as $item) {
			$table_id = $item['id'];
			$table_link = '<a href="'.url(1).'/'.$item['sef_title'].'">'.$item['title'].'</a>';

			$table->tr(
				$table->td($table_id, TRUE).
				$table->td($table_link)
			);
		}
		$table->close();
		$this->body .= $table->output();

		$this->output = box($this->icon['about'].' '._('Skeleton Module'), $this->body);
	}

	#### VIEW ##################################################################
	function view() {
		$item = $this->model->getItemBySef(url(2));

		if ($item['disabled']) $body = notice(_('Sorry, this item has been disabled.'), 'info', TRUE);
		else $body = nl2br($item['body']).'<br /><br /><a href="'.url(1).'">'.$this->icon['left'].' '._('Back').'</a>';

		$this->output = box($item['title'], $body);
	}
}
?>